{% extends './layout/default' %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, accountIds, tagIds, start, end) }}
{% endblock %}

{% block content %}

    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'accounts'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="accountsHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'tags'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="tagsHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'account_per_tag'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="accountPerTagHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_tag'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="tag-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_tag'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="tag-in-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="category-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="category-in-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_budget'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="budgets-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_source_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="source-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_source_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="source-in-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_destination_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="dest-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_destination_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="dest-in-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% for tag in tags %}
        <div class="row">
            <div class="col-lg-12">
                <div class="box main_budget_chart">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'income_and_expenses'|_ }} ({{ tag.tag }})</h3>
                    </div>
                    <div class="box-body">
                        <canvas class="main_tag_canvas"
                                data-url="{{ route('chart.tag.main', [accountIds, tag.id, start.format('Ymd'), end.format('Ymd')]) }}"
                                id="in-out-chart-{{ tag.id }}" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                    </div>
                    <div class="box-footer">
                        <p class="text-info"><em>{{ 'tag_report_chart_single_tag'|_ }}</em></p>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
    <div class="row">
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'average_spending_per_destination'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="avgExpensesHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'average_earning_per_source'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="avgIncomeHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="topExpensesHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="topIncomeHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block scripts %}
    <script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/bootstrap-sortable.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>

    <script type="text/javascript" src="v1/js/ff/reports/all.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        // to report another URL:
        var startDate = '{{ start.format('Ymd') }}';
        var endDate = '{{ end.format('Ymd') }}';
        var accountIds = '{{ accountIds }}';
        var tagIds = '{{ tagIds }}';


        var accountsUrl = '{{ route('report-data.tag.accounts', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var tagsUrl = '{{ route('report-data.tag.tags', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var accountPerTagUrl = '{{ route('report-data.tag.account-per-tag', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';

        // pie charts:
        var tagOutUrl = '{{ route('chart.tag.tag-expense', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var tagInUrl = '{{ route('chart.tag.tag-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var categoryOutUrl = '{{ route('chart.tag.category-expense', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var categoryInUrl = '{{ route('chart.tag.category-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var budgetsOutUrl = '{{ route('chart.tag.budget-expense', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var sourceOutUrl = '{{ route('chart.tag.source-expense', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var sourceInUrl = '{{ route('chart.tag.source-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var destOutUrl = '{{ route('chart.tag.dest-expense', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var destInUrl = '{{ route('chart.tag.dest-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';

        var avgExpensesUrl = '{{ route('report-data.tag.avg-expenses', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var topExpensesUrl = '{{ route('report-data.tag.top-expenses', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var avgIncomeUrl = '{{ route('report-data.tag.avg-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var topIncomeUrl = '{{ route('report-data.tag.top-income', [accountIds, tagIds, start.format('Ymd'), end.format('Ymd')]) }}';

    </script>
    <script type="text/javascript" src="v1/js/ff/reports/tag/month.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>

{% endblock %}

{% block styles %}
    <link rel="stylesheet" href="v1/css/bootstrap-sortable.css?v={{ FF_VERSION }}" type="text/css" media="all" nonce="{{ JS_NONCE }}">
{% endblock %}
